<template>
	<view class="padding32" :style="{marginTop:tabh}">
		
		<view class="" :style="{height:$store.state.company_status==0?'154rpx':'110rpx'}">
			<u-navbar  bgColor="#f5f5f5" :autoBack="false" title="" :height='$store.state.company_status==0?100 : 80' leftIconColor="#f5f5f5">
				<view class="" slot="center" style='width: 100%;'>
					<view style="width:90%;margin: 0 auto;"> 
						<view class="searchBox flexJBC mt24"     @click="$my.go('/pages/search/index')">
							<view class="leftInput">
								<u-input placeholderStyle="color:#999;font-size:28rpx" placeholder="请输入搜索内容" border="none"
									v-model="inputValue" autoBlur disabled="">
									<view class="" slot='prefix'>
										<u-icon name="search" size="48rpx" color="#999"></u-icon>
									</view>
								</u-input>
							</view>
							<view class="searchbtn cof fontS32 bgcred" >
								搜索
							</view>  
						</view>
					</view>
					<Certification/>
				</view>
			</u-navbar>
		</view> 
		<view class="swiperBox "  v-if="swiperList.length>0"> 
			<view class="u-demo-block">
				<u-swiper height="220rpx" radius="20rpx" keyName='image' :list="swiperList" @change="e => swiperCurrent = e.current">
					<view slot="indicator" class="indicator">
						<view class="indicator__dot" v-for="(item, index) in swiperList" :key="index" :class="[index === swiperCurrent && 'indicator__dot--active']">
						</view>
					</view>
				</u-swiper>
			</view>
		</view>
		<!-- 金刚 --> 
		<view class="mt24">
			<scroll-view scroll-x="true" @scrolltoupper='jingangLi=1' @scrolltolower='jingangLi=2'>
				<view class="flex"> 
					<view style="margin-right: 25px; "class='flexcenter mb32'  v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex" @click="$my.go(baseListItem.tab+'?id=' + baseListItem.id)" v-if="baseListItem.is_top">
						<view class="" style="width: 96rpx;height: 96rpx;">
							<image :src="baseListItem.image"   style="width: 96rpx;height: 96rpx;"></image>
						</view>
						<view class="fontS24 elipes1" style="margin-top: 8rpx;">{{baseListItem.name}}</view>
					</view>
				</view>
			</scroll-view>
			<view class="jingangLi flex">
				<view class="li " :class="jingangLi==1?'liactive':''"></view>
				<view class="li " :class="jingangLi==2?'liactive':''"></view>
			</view> 
		</view>
		<!-- 品牌特卖 -->
		<view class=" whiteBox speacilSale" style="padding: 0;overflow: hidden;margin-top: 36rpx;" v-if="teMai && specialList.length>0" @click="$my.go(teMai.tab+'?id='+teMai.id)">
			<view class="top">
				<view class="flex"> 
					<view class="fontS32 fw7">
						{{teMai.name}}
					</view>
					<!-- <view class="fontS24" style="margin-left: 12rpx;">
						全场包邮
					</view> -->
				</view>
			</view>
			<scroll-view scroll-x="true" class="relative" style="margin-top: -38rpx;">
				<view class="flex  paddingLR24" style="flex-wrap: nowrap;">
					<view class="center " style="width:144rpx;margin-right: 22rpx;" @click.stop="$my.go('/myPackageA/goodsAndFacton/goodsDetails?id='+item.id)" v-for="(item,index) in specialList" :key="index">
						<view class="" style="width: 144rpx;height: 144rpx;"> 
							<image  :src="item.image"   style="width: 144rpx;height: 144rpx;border-radius: 10rpx;"></image>
						</view>
						<!-- 售卖价 -->
						<view class="homeRed fw8">
							<text class="fontS16">￥</text>
							{{item.price}} 
						</view>
						<!-- 横线价格 -->
						<view class="co9 fontS20" style="text-decoration: line-through;">
							￥{{item.ot_price}}
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 销量排行  -->
		<view class="sortBox  mt32 ">
			<view class="flex mb24">
				<view  @click="tabListActive=item.id;getHotList()" :class="tabListActive==item.id?'tabListActive fontS32 co3 fw6' :'co6'" v-for="item in tabList" :key="item.id" style="margin-right: 48rpx;">
					{{item.name}}
				</view>
			</view>
			<scroll-view scroll-x="true" @scrolltolower="getHotList(true)">
				<view class="flex" style="flex-wrap: nowrap;">
					<view class="lis bgf" style="height: 510rpx;" v-for="(item,index) in hotList" :key="index" @click="$my.go('/myPackageA/goodsAndFacton/goodsDetails?id='+item.id)">
						<view class="" style="width: 296rpx;height: 296rpx;">
							<image :src="item.image"  style="width: 296rpx;height: 296rpx;border-radius:20rpx 20rpx 0 0;" mode='aspectFill'>  
							</image>
						</view>
						<view class="bottomBox">
							<view class="goodsname fontS28 elipes2">{{item.product_name}}</view>
							<view class="wantbuynum fontS24" >
								{{item.browse}}人想买
							</view>
							<view class="flexJBC" style="margin-top: 8rpx;">
								<view class="unitPrice">
									<view class="flex" >
										<text class="fontS32">
											<text class="fontS24">￥</text>{{item.price}}</text>
										<view class="co9 fontS20" style="text-decoration:line-through;margin-left: 12rpx;">￥{{item.ot_price}} </view>
									</view>
								</view>
								<!-- <view class="more">
									<view class="">.</view>
									<view class="">.</view>
									<view class="">.</view>
								</view> -->
							</view>
						</view>
					</view>
					<!-- <view class="homeRed">
						更多
					</view> -->
				</view>
			</scroll-view>
		</view>
		<list :list="list" type='1' v-if="list.length>0" :showSale='false'/>
		<TabBar :value="value" :changeValue='changeValue' />
		<Coupon :showCoupon='showCoupon' @showCouponClose='showCouponClose' :copuonList='copuonList' type='0'/>
	</view> 
</template>

<script>
	import List from '@/componentes/list.vue'
	import TabBar from '@/componentes/TabBar.vue'
	import Coupon from '@/componentes/coupon.vue'
	import Certification from '@/componentes/certification.vue'
	export default {
		data() { 
			return {
				jingangLi:1,
				showCoupon:false,
				copuonList:[],
				tabh:this.$store.state.tabh,
				hotPage:1,//销量和热销
				specialList:[],//品牌特卖列表
				swiperCurrent: 0, //轮播当前
				tabListActive:0, //当前销量排行
				tabList:[
					{id:0,name:'销量排行'},
					{id:1,name:'热销商品'},
					// {id:2,name:'降价商品'},
				],
				baseList: [],
				swiperList: [],
				inputValue: '',
				value: 0,
				page:1,
				hotList:[],//销量排行和热销排行
				list:[], //为你推荐
			};
		},
		
		onLoad() {
			this.getLunBo(); 
			this.getClassfiy()
			this.getList()
			this.getHotList()
			// 优惠券弹窗
			this.$my.post('/index/coupon/get_coupon',{type:0,page:1,limit:100}).then(res=>{
				if(res.code==200){
					this.copuonList=res.data
					if(this.copuonList.length>0){
						this.showCoupon=true
					} 
					this.copuonList.forEach(item=>{
						this.$set(item,'showInfo' ,false) //是否显示使用说明
					})
					this.$my.post('/index/coupon/receiveCoupon')
				} 
			})
			this.$my.get('/index/user/get_user_info').then(res=>{
				if(res.code==200){
					uni.setStorageSync('userInfo',res.data)
					this.$store.commit('changecompany_status',res.data.company_status)
				}
			})
		},
		computed:{
			teMai(val){
			    return this.baseList.find(item=>{
				   return item.is_top==0
			   })
			}
		}, 
		components: {
			List,TabBar,Coupon,Certification
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			
			// 关闭优惠卷弹窗
			showCouponClose(val){ 
				this.showCoupon=val
			},
			// 轮播图
			getLunBo(){
				this.$my.post('/index/com/getAd',{type:1}).then(res=>{
					if(res.code==200){
						this.swiperList=res.data
					}
				})
			},
			// 分类 和品牌特卖
			getClassfiy(){
				this.$my.post('/index/Index/get_type').then(res=>{
					if(res.code==200){
						this.baseList=res.data
						// 品牌特卖
						this.baseList.forEach(item=>{
							if(item.is_top==0){
								this.$my.post('/index/Product/getIndexTypeProduct',{type_id:item.id,page:1,limit:10}).then(res=>{
									if(res.code==200){
										this.specialList=res.data.data
									}
								})
							}
						})
					}
				})
			},
			// 销量排行和热销商品
			getHotList(val){
				if(val){
					this.hotPage++
				}else{
					this.hotPage=1;
				}
				this.$my.post('/index/Product/indexProoduct',{page:this.hotPage,limit:20,indexType:this.tabListActive}).then(res=>{
					if(res.code==200){
						if(!val){
						  this.hotList=[]
						} 
						this.hotList =this.hotList.concat(res.data.data)
					}
				})
			},
			
			// 推荐商品 
			getList(){ 
				let _this=this
				this.$my.post('/index/Product/indexRecomment',{page:this.page,limit:2,}).then(res=>{
					if(res.code==200 && res.data.data.length>0){
						this.list = this.list.concat(res.data.data)
					} 
				})
				console.log(this.list)
			},
		
			changeValue(e) {
				this.value = e
			}
		}
	}
</script>
<style lang="scss" scoped>
	.jingangLi{
		width: 64rpx;
		height: 4rpx;
		border-radius: 2rpx;
		background: #E0E0E0;
		position: absolute;
		left: 50%;
		overflow: hidden;
		transform: translateX(-50%);
		
		.li{
			width: 32rpx;
			height: 4rpx;
		}
		.liactive{
			background-color: $red;
		}
	}
	.sortBox{
		.lis {
			width:296rpx;
			border-radius: 20rpx;
			margin-right: 28rpx;
			.bottomBox {
				background: #fff;
				padding: 20rpx 16rpx;
				box-sizing: border-box;
				border-radius: 0 0 20rpx 20rpx;
				.goodsname {
					color: #000;
					line-height: 39rpx;
				}
				.wantbuynum {
					color: #999;
					margin: 12rpx 0;
				}
				.more {
					width: 36rpx;
					// height: 20rpx;
					line-height: 8rpx;
					text-align: center;
					color: #999;
				}
			}
		}
	}
	.speacilSale {
		height: 304rpx;
		.top {
			padding:24rpx;
			box-sizing: border-box;
			height: 112rpx;
			background: linear-gradient( #FACED2 20%,  #fff 100%);
		}
	}

	.swiperBox {
		margin-top: 20rpx;
		.indicator {
			@include flex(row);
			justify-content: center;

			&__dot {
				height: 6px;
				width: 6px;
				border-radius: 100px;
				background-color: rgba(255, 255, 255, 0.35);
				margin: 0 5px;
				transition: background-color 0.3s;

				&--active {
					background-color: #ffffff;
				}
			}
		}

		.indicator-num {
			padding: 2px 0;
			background-color: rgba(0, 0, 0, 0.35);
			border-radius: 100px;
			width: 35px;
			@include flex;
			justify-content: center;

			&__text {
				color: #FFFFFF;
				font-size: 12px;
			}
		}
	}

	page {
		padding-bottom: 200rpx;
	}

	.searchBox {
		.leftInput {
			flex: 1;
			padding: 0 18rpx;
		}

		.searchbtn {
			height: 80rpx;
			line-height: 80rpx;
			padding: 0 18rpx;
		}

		width: 100%;
		height: 80rpx;
		border-radius: 16rpx;
		border: 1rpx solid $red;
		overflow: hidden;
		box-sizing: border-box;
	}
</style>

